#三乐购物系统

print('''
***********三乐购物系统***********
*************请登录！************
	''')
# 用户输入用户名及密码
d = 0
while True:
	name = input("请输入您的用户名：")
	password = input("请输入您的密码：")

	# 登录验证
	user = {'fan':'123','wen':'123456','hao':'123456'}
	if name == 'q' or password == 'q':
		exit(0)
	for user_name in user:
		if user_name == name and user[user_name] == password:
			print(f"\n*****{user_name}欢迎进入三乐购物系统！*****")
			d = 1
			break
	else:
		print("用户名或密码错误！请重新输入！")
	if d == 1:
		break

#用户输入预算和操作
print('''
**********三乐购物系统***********
**********请输入您的操作**********
**********01:查看商品信息*********
**********02:查看已购信息*********
	''')
while True:
	budget = input("请输入您的预算：")
	if budget.isdigit():
		budget = int(budget)
		break
	elif budget == 'q':
		exit(0)
	else:
		print("输入错误！请重新输入！")
while True:
	action = input("请输入您要进行的操作：")
	if action == '01' or action == '02':
		break
	elif action == 'q':
		exit(0)
	else:
		print("输入有误！请重新输入！")

#定义购物清单
print("*************商品信息*************\n")
goods = [('苹果',5),('香蕉',4),('草莓',12),('西瓜',3),('桃子',7)]
shopping_list = []

#用户购买商品
if action == '01':
	for goods_name,goods_price in enumerate(goods):
		print(f"{goods_name} 的价格是：{goods_price} /斤")
		print(f"SC{goods_name:0>3}",goods_price)
		print(goods_name,goods_price)
	print("*********************************\n\n")
	while True:
		enter_number = input("请输入您要购买的商品编号：")
		if enter_number.isdigit() and int(enter_number)>-1 and int(enter_number)<len(goods):
			enter_number = int(enter_number)
			goods_item = goods[enter_number]
			if goods_item[1] <= budget:
				shopping_list.append(goods_item)
				budget -= goods_item[1]
				print(f"您选购的商品是{goods_item[0]}，费用：{goods_item[1]}，剩余金额：{budget}")
			else:
				print("您的预算不足，请重新选择!")
		elif enter_number == 'q':
			print("\n\n*************订单详情************\n")
			for item_name,item_price in enumerate(shopping_list,1):
				print(f"F{item_name:0>4}",item_price)
			print(f"\n您的余额为{budget}")
			exit(0)
		else:
			print("输入有误！请重新输入！")
else:
	if len(shopping_list) == 0:
		print("您还未购买任何商品！快去购物吧！")
